﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SwitchMiner.Models;
using SwitchMiner.Interfaces;

namespace SwitchMiner.Controlers
{
    public class SwitchControler
    {private List<SwitchModel> _model = null;
        private IModelNotification _Callback = null;

        public SwitchControler(IModelNotification callback, List<SwitchModel> model)
        {
            _model = model;
            _Callback = callback;
            if (_model.Count > 0 && _Callback != null)
            {
                _Callback.SwitchModelsChanged(_model);
            }
        }

        public List<SwitchModel> GetModel()
        {
            return _model;
        }
        public void AddModel(SwitchModel model)
        {
            if (_model != null)
            {
                if (_model.Contains(model) == false)
                {
                    /*foreach (SwitchModel innerModel in _model)
                    {
                        if (innerModel.MinerName == model.MinerName 
                            && innerModel.ParameterName == model.ParameterName
                            && innerModel.Duration == model.Duration)
                        {
                            return;
                        }
                    }*/
                    _model.Add(model);
                    if (null != _Callback)
                    {
                        _Callback.SwitchModelsChanged(_model);
                    }
                }
            }
        }
        public void RemoveModel(SwitchModel model)
        {
            if (_model != null)
            {
                if (_model.Contains(model) == true)
                {
                    _model.Remove(model);
                    if (null != _Callback)
                    {
                        _Callback.SwitchModelsChanged(_model);
                    }
                }
            }
        }
    }
}
